<template>
  <q-page class="q-pa-md">
    <div class="row items-center">
      <div class="q-pb-md text-h5">
        {{ pageTitle }}
        <span class="text-subtitle1">列表</span>
      </div>
      <q-space></q-space>
      <search-bar-toggle-btn v-model="searchBarVisibility"></search-bar-toggle-btn>
    </div>
    <!-- 查询菜单 -->
    <div class="q-pa-sm shadow-2 q-mb-md items-center" v-show="searchBarVisibility">
      <div class="row q-col-gutter-sm">
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm">
          <div class="col-4 text-right searchbar-label">空托盘转移单单号</div>
          <div class="col-8">
            <easy-input v-model="fpsReq.containerMoveNum" :readonly="listDataLoadingState" />
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm">
          <div class="col-4 text-right searchbar-label">创建日期从</div>
          <div class="col-8">
            <easy-input v-model="fpsReq.createDtBegin" use-date-picker append-icon-show :readonly="listDataLoadingState" />
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm">
          <div class="col-4 text-right searchbar-label">创建日期至</div>
          <div class="col-8">
            <easy-input v-model="fpsReq.createDtEnd" use-date-picker append-icon-show :readonly="listDataLoadingState" />
          </div>
        </div>
        <div class="col-shrink row q-col-gutter-sm">
          <div class="col">
            <q-toggle v-model="fpsReq.isSuccess" :disable="listDataLoadingState" @update:model-value="loadListData(2)"
              dense toggle-indeterminate class="q-ma-xs" label="是否成功"/>
          </div>
        </div>
      </div>
      <div class="row q-pt-sm">
        <div class="q-mr-sm">
          <q-btn :disable="listDataLoadingState" @click="loadListData(2)" color="primary" icon="search" label="查询" />
        </div>
      </div>
    </div>
    <div class="shadow-2">
      <q-table @request="fpsAssist.onDataTableRequest" :rows="$d.tableData" :columns="fpsInfo.columnsInfo"
        separator="cell" row-key="backId" v-model:pagination="fpsInfo.paginationInfo" :visible-columns="fpsInfo.visibleColumns"
        dense flat :hide-pagination="true" :loading="listDataLoadingState" color="primary" binary-state-sort hide-selected-banner
        @row-dblclick="(evt,row)=>{fpsNav.gotoDetail(row.backId)}">
        <template v-slot:top="props">
          <!--填充所有剩余空间-->
          <q-space />
          <table-col-options-cfg v-model:table-columns="fpsInfo.columnsInfo"
            v-model:visible-columns="fpsInfo.visibleColumns"
            @update-col-options-for-save="fpsAssist.saveColOptions">
          </table-col-options-cfg>
          <q-btn flat dense :icon="props.inFullscreen ? 'fullscreen_exit' : 'fullscreen'"
            :title="props.inFullscreen ? '退出全屏' : '全屏显示'" @click="props.toggleFullscreen" class="q-ml-sm"
            :ripple="false" />
        </template>
        <!--操作列插槽-->
        <template v-slot:body-cell-operation="props">
          <q-td :props="props" auto-width>
            <q-btn color="primary" label="查看" class="q-mr-xs btn-in-row" :dense="true"
              @click="evt => fpsNav.gotoDetail(props.row.backId, evt)" />
          </q-td>
        </template>
        <template v-slot:body-cell-isSuccess="props">
          <q-td :props="props" auto-width>
            <q-badge :color="props.row.isSuccess?'positive':'grey-6'"
              :label="props.row.isSuccess ? '是' : '否'" />
          </q-td>
        </template>
        <template v-slot:body-cell-result="props">
          <q-td :props="props" auto-width>
            <q-badge :color="props.row.result === '0' ? 'grey-6' : 'positive'"
              :label="props.row.result === '0' ? '否' : '是'" />
          </q-td>
        </template>
        <template v-slot:no-data>
          <div class="full-width items-center justify-center row">
            <q-icon name="error_outline" />
            无数据
            <q-btn flat icon="refresh" :loading="listDataLoadingState"
              :disable="listDataLoadingState" dense title="刷新" size="sm" class="q-ml-sm" @click="loadListData"></q-btn>
          </div>
        </template>
        <template v-slot:bottom>
          <paging-bar :pageNo="fpsReq.pageNo" :pageSize="fpsReq.pageSize" :totalAmount="fpsInfo.totalAmount"
            @pagesize-changed="fpsAssist.onPageSizeChanged" @go-to-page="fpsNav.gotoPage"
            :loading-state="listDataLoadingState" />
        </template>
      </q-table>
    </div>
  </q-page>
</template>

<script lang="ts">
export default {
  name: 'lpnMoveBackLogList'
}
</script>
<script lang="ts" setup>
import {useTitleHelper} from '@njt/foundation/hooks/titleHelper';
import {reactive, ref} from 'vue';
import {GetLpnMoveBackLogListReq, GetLpnMoveBackLogListResp, LpnMoveBackLog} from 'src/defs/sf/lpnMoveBackLog';
import {ColumnInfo} from '@njt/foundation/defs/comm';
import {useFpsHelper} from '@njt/foundation/hooks/fpsHelper';

const pageTitle = '空托盘转移单回告日志'
useTitleHelper(pageTitle)

const $d = reactive({
  tableData: [] as LpnMoveBackLog[]
})

let fpsReq: GetLpnMoveBackLogListReq = reactive({
  containerMoveNum: null,
  isSuccess: null,
  createDtBegin: null,
  createDtEnd: null,
  isDescending: false,
  orderBy: null,
  pageNo: 1,
  pageSize: 40
})

const columnsDefine: ColumnInfo[] = [
  {
    label: '操作',
    name: 'operation',
    field: 'operation',
    align: 'left',
    defVisible: true,
    defOrder: 1,
  },
  {
    label: '序号',
    name: 'backId',
    field: 'backId',
    align: 'left',
    defVisible: true,
    sortable: true,
    defOrder: 2,
  },
  {
    label: '是否成功',
    name: 'isSuccess',
    field: 'isSuccess',
    align: 'left',
    defVisible: true,
    defOrder: 3,
  },
  {
    label: '错误信息',
    name: 'backMsg',
    field: 'backMsg',
    align: 'left',
    defVisible: true,
    defOrder: 4,
    format: (val: string | null) => {
      return (val && val.length>130)?`${val.slice(0, 129)}...`:val
    }
  },
  {
    label: '顺丰请求ID',
    name: 'requestId',
    field: 'requestId',
    align: 'left',
    defVisible: true,
    defOrder: 5,
  },
  {
    label: '仓库编码',
    name: 'warehouseCode',
    field: 'warehouseCode',
    align: 'left',
    defVisible: true,
    defOrder: 6,
  },
  {
    label: '顺丰空托盘转移单单号',
    name: 'containerMoveNum',
    field: 'containerMoveNum',
    align: 'left',
    defVisible: true,
    defOrder: 7,
  },
  {
    label: '是否收货完成',
    name: 'result',
    field: 'result',
    align: 'left',
    defVisible: true,
    defOrder: 8,
  },
  {
    label: '预留字段1',
    name: 'userDef1',
    field: 'userDef1',
    align: 'left',
    defVisible: false,
    defOrder: 9,
  },
  {
    label: '预留字段2',
    name: 'userDef2',
    field: 'userDef2',
    align: 'left',
    defVisible: false,
    defOrder: 10,
  },
  {
    label: '预留字段3',
    name: 'userDef3',
    field: 'userDef3',
    align: 'left',
    defVisible: false,
    defOrder: 11,
  },

  {
    label: '创建人',
    name: 'createP',
    field: 'createP',
    align: 'left',
    defVisible: true,
    defOrder: 12,
    format: (val: string,row: LpnMoveBackLog) => $f.fmt.userDisp(val, row.createPn)
  },
  {
    label: '创建时间',
    name: 'createDt',
    field: 'createDt',
    align: 'left',
    defVisible: true,
    defOrder: 13,
    format: (val: string) => $f.fmt.dtFmtFullNoSec(val)
  },
]

let listDataLoadingState = ref(false)
const loadListData = function (resetFpsReq?: number){
  if (resetFpsReq) {
    if (resetFpsReq >= 1) {
      fpsReq.pageNo = 1
    }
    if (resetFpsReq >= 2) {
      fpsReq.orderBy = ''
      fpsReq.isDescending = false
    }
  }
  listDataLoadingState.value = true
  $f.axios
    .get<GetLpnMoveBackLogListResp>('/mhlbc/sf/get-lpn-move-back-log-list',{params: fpsReq})
    .then((resp) => {
      if (resp.data.createDtBegin)
        resp.data.createDtBegin = $f.fmt.dtFmtDateOnly(resp.data.createDtBegin)
      if (resp.data.createDtEnd)
        resp.data.createDtEnd = $f.fmt.dtFmtDateOnly(resp.data.createDtEnd)
      fpsAssist.handleGenericFpsResp(resp.data)
      $d.tableData = resp.data.lpnMoveBackLogs
      fpsAssist.saveFpsReq(fpsReq)
    })
    .catch((err) => {
      $f.ui.showNotifyFailed($f.getAxiosErrMsg(err))
    })
    .finally(() => {
      listDataLoadingState.value = false
    })
}

const {
  fpsInfo,
  fpsNav,
  fpsAssist,
  searchBarVisibility
} = useFpsHelper('/sf/lpn-move-back-log',
  '/sf/lpn-move-back-log/detail',
  null,
  null,
  fpsReq,columnsDefine,
  null,
  loadListData
)

</script>

<style scoped>

</style>
